<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no"/>
    <meta charset="utf-8">
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
    <title>Libraries</title>
</head>
<body>
<div id="react-container"></div>
  <script type="text/babel">

    const { Component } = React
    const { render } = ReactDOM

    const Expandable = ComposedComponent =>
      class Expandable extends Component {

          constructor(props) {
              super(props)
              const collapsed = (props.hidden && props.hidden === true) ? true : false
              this.state = {collapsed}
              this.expandCollapse = this.expandCollapse.bind(this)
          }

          expandCollapse() {
              this.setState(prevState => ({
                collapsed: !prevState.collapsed
              }))
          }

          render() {
              return <ComposedComponent
                          expandCollapse={this.expandCollapse}
                          {...this.state}
                          {...this.props} />
          }
      }

    const ShowHideMessage = ({children, collapsed, expandCollapse}) =>
      <p onClick={expandCollapse}>
          {(collapsed) ?
              children.replace(/[a-zA-Z0-9]/g, "x") :
              children}
      </p>

    const HiddenMessage = Expandable(ShowHideMessage)

    render(
        <HiddenMessage hidden={true}>This is a hidden message</HiddenMessage>,
        document.getElementById('react-container')
    )


  </script>
</body>
</html>
